% !TEX root = verslag_main.tex
\section{The State-space model}
\label{sec:ssmodel}

The true model of the seesaw is nonlinear. To be able to construct an LQR-type controller we will work with a linearized continuous time model around the non-stable equilibrium point $(\theta = 0)$. The four states of the system are the position of the cart $x$ and the speed of the cart $\dot{x}$, the angle and the speed of the angle $\theta$ and $\dot{\theta}$ respectively. The linearized state-space model then consists of a linear state equation of the form $\dot{x}=Ax+Bu$,
$$ 
\begin{bmatrix}  \dot{x} \\ \dot{\theta} \\ \ddot{x} \\ \ddot{\theta}\end{bmatrix}  = 
\begin{bmatrix} 
0 & 0 & 1 & 0  \\ 
0 & 0 & 0 & 1 \\ 
a_{3,1} & a_{3,2} & a_{3,3} & a_{3,4} \\ 
a_{4,1} & a_{4,2} & a_{4,3} & a_{4,4} \end{bmatrix} 
\begin{bmatrix}  x \\ \theta \\ \dot{x} \\ \dot{\theta} \end{bmatrix}  + 
\begin{bmatrix} 0 \\ 0 \\ b_3 \\ b_4\end{bmatrix} V$$
where the coefficients $a_{i,j}$ and $b_i$ are found from the linearisation of the true model. For the open loop analysis, we assume that the states can be measured directly and thus for the output relation $y=Cx$ the C matrix is equal to the identity matrix.

The goal of this exercise is to design a controller to keep the seesaw levelled at a specified angle. We will now discuss the properties of this state-space model by means of an open-loop analysis. The following topics will be investigated
\begin{itemize}
\item The poles and zeros of the open-loop system
\item Stability of the system
\item Observability of the system
\item Controllability of the system
\end{itemize}

\subsection{Open-loop analysis}
Since we are working with a continuous time system, all the poles should be in the left half-plane for stability. This means  that each pole should have a negative real part.
The poles of the system are equal to the eigenvalues of the A-matrix. The poles of the open-loop system are shown in figure \ref{fig:polesOpenLoop}. These poles are $2.9006, -1.5310 \pm 0.5114i, -16.7635$. There is one eigenvalue with a positive real part meaning that the given system is unstable because there is one unstable mode corresponding with this eigenvalue. There are no transmission zeros.

\setlength\figureheight{3cm} \setlength\figurewidth{5cm}
\begin{figure}[h]
\centering
  \subfloat[open-loop system]{ \label{fig:polesOpenLoop} \input{img/polesOpenLoop.tikz}}
  \subfloat[closed-loop system]{ \label{fig:polesClosedLoop} \input{img/polesClosedLoop.tikz}}
  \caption{Plot of the poles of the open-loop and closed loop system}
\end{figure}

The Matlab command \emph{ctrb(A,B)} allows us to calculate the controllability matrix $\mathcal{C}$ for the system. Because $rank(\mathcal{C}) = 4$ the system is controllable. As shown earlier there was one unstable pole of the system. Because the system is controllable this mode is stabilizable therefore the system $(A, B)$ is stabilizable. 
The observability matrix $\mathcal{O}$ can be calculated with the Matlab command \emph{obsv(A,C)}. The rank of $\mathcal{O} = 4$ meaning that the system is observable. We conclude that the system is also detectable since the unstable mode is observable. These results are summarized in table \ref{table:openLoopAnalysis}.

In the next section \ref{sec:controller} we will discuss the design of an LQR controller for this unstable system. We want this controller to be able to stabilize the seesaw as well as being able to track a given signal with desirable transient effects and sufficiently rapid responsiveness. 

\begin{table}[H]
\centering
	\begin{tabular}{| c | c | c | c |}
	\hline 
	Modes & Stable? & Stabilizable? & Detectable? \\ \hline \hline
	2.9006 & No & Yes & Yes \\ \hline
	-1.5310 $\pm$ 0.5114i & Yes & Yes & Yes \\ \hline
	-16.7635 & Yes & Yes & Yes \\ \hline
	\end{tabular}
	\vspace{0.1cm}
	\caption{Summary of the open-loop analysis}
	\label{table:openLoopAnalysis}
\end{table}